<template>
	<view class="ys">
		<view class="form">
			<uni-section title="是否需要交台票 " type="line">
				<view class="inputbox">
					<uni-data-checkbox v-model="is_ticket" :localdata="rolelist"></uni-data-checkbox>
				</view>
			</uni-section>
			<uni-section title="台票价格" type="line">
				<view class="inputbox">
					<uni-easyinput v-model="ticket_money" trim placeholder="请输入台票价格" clearSize="20"></uni-easyinput>
				</view>
			</uni-section>
			<uni-section title="迟到/早退罚款金额" type="line">
				<view class="inputbox">
					<uni-easyinput v-model="sign_fine" trim placeholder="请输入迟到/早退罚款金额" clearSize="20"></uni-easyinput>
				</view>
			</uni-section>
			<uni-section title="上班时间 " type="line">
				<view class="inputbox pickerbox">
					<picker mode="time" :value="work_time" @change="bindWorkTimeChange">
						<view class="uni-input">{{work_time || '请选择'}}</view>
					</picker>
				</view>
			</uni-section>
			<uni-section title="下班时间" type="line">
				<view class="inputbox pickerbox">
					<picker mode="time" :value="close_time" @change="bindEndTimeChange">
						<view class="uni-input">{{close_time || '请选择'}}</view>
					</picker>
				</view>
			</uni-section>
		</view>

		<button class="btn" @click="confSave" :loading="loading" :disabled="loading">提交</button>
	</view>
</template>

<script>
	import {
		confSave,
		storeConf
	} from "@/api/user.js"
	export default {
		data() {
			return {
				is_ticket: '',
				ticket_money: '',
				rolelist: [{
					text: '是',
					value: 1

				}, {
					text: '否',
					value: 0
				}],
				loading: false,
				sign_fine: '',
				work_time: '',
				close_time: ''
			}
		},
		onLoad() {
			this.storeConf()
		},
		methods: {
			storeConf() {
				storeConf().then(res => {
					if (res.code == 0) {
						this.is_ticket = res.data.is_ticket
						this.ticket_money = res.data.ticket_money
						this.sign_fine = res.data.sign_fine
						this.work_time = res.data.work_time
						this.close_time = res.data.close_time
					}
				})
			},
			bindWorkTimeChange(e) {
				this.work_time = e.detail.value
			},
			bindEndTimeChange(e) {
				this.close_time = e.detail.value
			},
			confSave() {
				let that = this
				if (this.is_ticket === '') {
					return uni.$showMsg('请选择是否需要交台票')
				}
				if (this.is_ticket == 1 && this.ticket_money == '') {
					return uni.$showMsg('请输入台票价格')
				}
				if (this.sign_fine == '') {
					return uni.$showMsg('请输入签到金额')
				}
				that.loading = true
				confSave({
					is_ticket: this.is_ticket,
					ticket_money: this.ticket_money,
					sign_fine: this.sign_fine,
					work_time: this.work_time,
					close_time: this.close_time
				}).then(res => {
					uni.$showMsg(res.msg)
					if (res.code == 0) {
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					} else {
						that.loading = false
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.ys {
		.inputbox {
			width: 96%;
			margin: 0px auto;
		}

		.form {
			padding-bottom: 15px;
			background: #fff;
		}

		.pickerbox {
			height: 37px;
			border: 1px solid #dcdfe6;
			line-height: 37px;
			padding-left: 10px;
			box-sizing: border-box;
			border-radius: 5px;
			color: #333;
		}

		.btn {
			button {
				color: #fff;
				font-size: 16px;
				letter-spacing: 1px;
				margin: 30px auto;
				width: 96%;
			}
		}
	}
</style>